// TSP常见类型
// JS原始类型
let num22: number = 123
let str22: string = "hello"
let bool22: boolean = true
let und22: undefined = undefined
let nul22: null = null

// ES2020新加入
let sym22: symbol = Symbol("123")
let bigInt22: bigint = 123n

// 数组类型
let arr333: number[] = [1, 2, 3, 4]
let number1333: Array<number> =  [1, 2, 3, 4, 5]
let testArray333: Array<(boolean | number)> = [1, 2, true]

// 联合类型(typeA | typeB)
let arr1333: (number | string)[] =  [1, 'a', 2, 'b']
let a1333: (number | string) = 1

// 类型别名 type  TestType = (number | string)[]
type TestType33 = (number | string)[]
let arr222: TestType33 = [1, 2, '3', '4']

type AllType22 = (number | string | boolean | null | undefined | object)
let arr22: AllType22[] = [1 , '1', false, null, undefined, {'array': 1}]

// 对象类型
let testObj: {
    name: string,
    age: number,    
    func: (name: string) => number
} = {
    name: 'black',
    age: 25,
    func: (name) => name === 'black' ? 1 : 2
}

// 函数类型
let testFun: Function = (name: String): number => 1

console.log(typeof num22)
console.log(typeof str22)
console.log(typeof bool22)
console.log(typeof und22)
console.log(typeof nul22)
console.log(typeof sym22)
console.log(typeof bigInt22)
console.log(typeof arr333)
console.log(typeof number1333)
console.log(typeof testArray333)
console.log(typeof testObj)
console.log(typeof testFun)

//// 类型上下文中使用typeof
// 先定义一个变量
let p = {x:1 , y:2}
// 在上下文中使用typeof查询类型
function formatPoint(point: typeof p) {}
// 传入参数
formatPoint(p)
